package com.Object;

/**
 * @Author 小闽
 * @Date 2024/8/14 17:59
 * @PackageName: com.Object
 * @ClassName: Finalize
 * @Description: 垃圾回收机制
 * @Version 1.0
 */
public class Finalize {
    public static void main(String[] args) {
        Car car = new Car("宝马");
        car = null;
        System.gc();
        System.out.println("程序退出");

    }
}

class Car{
    private String name;

    public Car(String name) {
        this.name = name;
    }

    /**
     * 重写finalize方法
     * @throws Throwable
     */
    @Override
    protected void finalize() throws Throwable {
//        super.finalize();
        System.out.println("我们销毁汽车，释放系统资源" + name);
       }
}

